// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	1/6/2015 12:45:27 PM				
// -----------------------------

#include "FadePass.h"

FadePass::FadePass()
{
}

FadePass::~FadePass()
{
}

SoundSample FadePass::Apply(const SoundSample& input) const
{
	// Copy the Sample
	SoundSample sample = input;

	// Calculate the Offset
	UInt32 sampleOffset = (UInt32)((Offset * sample.SampleRate));

	// Fade the samples
	for (UInt32 i = sampleOffset; i < (sample.Count / sample.Channels); ++i)
	{
		Float t = (Float)(i - sampleOffset) / ((sample.Count / sample.Channels) - sampleOffset);
		Float v = Math::Lerp(StartVolume, EndVolume, t);

		for (UInt32 c = 0; c < sample.Channels; ++c)
			sample.Samples[(i * sample.Channels) + c] = input.Samples[(i * input.Channels) + c] * v;
	}

	return sample;
}